package cn.com.fuhuitong.main.mine.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import cn.com.fuhuitong.app.BaseApplication
import cn.com.fuhuitong.base.BaseViewModel
import cn.com.fuhuitong.http.BaseResponse
import cn.com.fuhuitong.http.HttpResponse
import cn.com.fuhuitong.http.ViewModelSubscribeListener
import cn.com.fuhuitong.main.home.entity.CharityListResponse
import cn.com.fuhuitong.main.home.entity.HomeResponse
import cn.com.fuhuitong.main.mine.entity.*
import cn.com.fuhuitong.main.mine.mode.MineManager
import cn.com.fuhuitong.main.order.mode.OrderManager
import io.reactivex.disposables.Disposable

class CollectionViewModel(application: Application) : BaseViewModel(application) {


    private val mineManager: MineManager = MineManager()

    val collectionListDataLiveData = MutableLiveData<HttpResponse<CollectionListResponse>>()

    val baseDataLiveData = MutableLiveData<HttpResponse<BaseResponse>>()

    private var page: Int = 1
    private var limit: Int = 20

    /**
     * 我的收藏
     */
    fun goodsCollection() {
        val listener =
            object :
                ViewModelSubscribeListener<CollectionListResponse>(collectionListDataLiveData) {}
        val goodsCollectionDisposable: Disposable = mineManager.goodsCollection(
            BaseApplication.userToken(), page.toString(), limit.toString(), listener
        )
        dispose.add(goodsCollectionDisposable)
    }

    /**
     * 删除收藏
     * */
    fun goodsCollection(goodsCollectionId: Int) {
        val listener =
            object : ViewModelSubscribeListener<BaseResponse>(baseDataLiveData) {}
        val delGoodsCollectionDisposable: Disposable = mineManager.delGoodsCollection(
            BaseApplication.userToken(), goodsCollectionId.toString(), listener
        )
        dispose.add(delGoodsCollectionDisposable)
    }

}